#!/usr/bin/env node

const http = require('https'),
      cheerio = require('cheerio'),
      log = console.log,
      addr = 'https://ke.segmentfault.com/free',
      baseURL = 'https://ke.segmentfault.com/';

http.get(addr,(res)=>{
  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
  log(res.headers);
  log();

  let html = '',$='';
  res.on('data',chunk=>html+=chunk);
  res.on('end',()=>{
    $ = cheerio.load(html);
    $('body').find('.card-title>a').each(function(){
        console.log($(this))                                  console.log($(this).html())                           const courseName = $(this).html(), ////???????          
        courseURL = $(this).attr('href');
                                                              log(courseName);                                      log(courseURL);
        log()                                                   
    })
                                                  
  })
})

//var cheerio = require('cheerio'),
//   //$ = cheerio.load('<h2 class="title">Hello world</h2>');
//
//   //$('h2.title').text('Hello there!');
//   //$('h2').addClass('welcome');
//
//   //console.log($.html());
                       
